package com.fundamental.classEx.agent;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;

public class AgentTest {

    private static Instrumentation _inst = null;

    public static void main(String[] args){

        long a1 = 10000000331333l;
        String astr = "10000000331333";

        long a2 = Long.parseLong(astr);
        System.out.println(a1 == a2);

    }
    /**
     * 热更写在premain，而不是classloader里的好处：1.不一定要写while，这样代码的侵入性比较低。2.直接可以重定义类文件，修改类的字节码，而不用循环去修改和初始化。
     * @param agentArgs
     * @param inst
     */
    public static void premain(String agentArgs, Instrumentation inst) {
        System.out.println("AopAgentTest.premain() was called.");

        /* Provides services that allow Java programming language agents to instrument programs running on the JVM.*/
        _inst = inst;

        /* ClassFileTransformer : An agent provides an implementation of this interface in order to transform class files.*/
        ClassFileTransformer trans = new AopAgentTransformer();

        System.out.println("Adding a AopAgentTest instance to the JVM.");

        /*Registers the supplied transformer.*/
        _inst.addTransformer(trans);
    }
}